#include "ProgressBar.h"

#include "_UI.h"
ProgressBar::ProgressBar(std::string uiObjectId, double defaultProgress,
                         const int x, const int y, const int width,
                         const int height)
    : UIObject(uiObjectId, x, y, width, height),
      currentProgress(defaultProgress) {
  background_ninePatch =
      new NinePatch(_UI::getInstance().progressBar_background_ninePatch);
  front_ninePatch =
      new NinePatch(_UI::getInstance().progressBar_front_ninePatch);
  UIObject::width = background_ninePatch->getWidth();
  UIObject::height = background_ninePatch->getHeight();
}
void ProgressBar::drawArea(const Rect& area) {
  background_ninePatch->drawArea(area, x, y, width, height);
  front_ninePatch->drawArea(area, x, y, int(width * currentProgress),
                            height);
  UIObject::drawArea(area);
}

void ProgressBar::setProgress(double progress) { currentProgress = progress; }

ProgressBar::~ProgressBar() {
  delete background_ninePatch;
  delete front_ninePatch;
}
